#ifndef _GRAPHICS_MAP_RENDERER_H
#define _GRAPHICS_MAP_RENDERER_H

#include <Ogre.h>
#include <vector>
#include "DwarfFort/StateListener.h"
#include <PagedGeometry.h>


struct CellDesignation;

namespace DwarfFort
{
	struct MapCell;
	class MapCellList;
}

namespace Graphics
{
	class MapBlock;	
	class MapCellMirrorList;
	class MaterialAtlas;
	class MapRenderer : public DwarfFort::StateListener, public Forests::PageLoader
	{
		// local copy of the scene manager to create map entities 
		Ogre::SceneManager			*mSceneManager;
		
		// pointer into DF.exe memory - the memory around map data pointer
		DwarfFort::MapCellList *mCellList;
		
		// material atlas used to render the terrain
		MaterialAtlas *mAtlas;

		// render queue in which the terrain is drawn
		Ogre::uint8			mQueueId;
		
		// mapping from cell ID's to cell content descriptions
		std::map<unsigned short,CellDesignation*> mCellDesignations;
		// loads map block meshes
		void loadMeshes();
		// gathers all materials used on the map
		void preParseMap();

		// base for the dynamic loading of terrain
		Forests::PagedGeometry *mPagedGeometry;
		// camera used for rendering the terrain
		Ogre::Camera *mCamera;
		// a dummy entity for testing, etc.
		Ogre::Entity *dummy;
		// ammount of z levels to remove from the top of the map while rendering 
		unsigned int mCutawayLevel;

		// DwarfFort::StateListener functions to monitor game state changes
		virtual void stateCreated();
		virtual void stateRemoved();
		virtual void stateUpdate(int level);
	public: 
		// PagedGeometry callback to generate the map on the fly
		void loadPage(Forests::PageInfo &page);
		MapRenderer(Ogre::SceneManager *sceneManager,Ogre::Camera *camera);
		~MapRenderer();


	}; // class MapRenderer

}; // namespace Graphics
#endif